<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=0.8">
    <title>剪贴板Markdown展示</title>
    <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
    <style>
        body {
            padding: 0px;
            font-family: "Microsoft YaHei", Arial, sans-serif;
            max-width: 1200px;
            margin: 0 auto;
            background-color: #f9f9f9;
        }
        .header {
            margin-bottom: 25px;
            color: #333;
            font-size: 22px;
            font-weight: 500;
        }
        #pasteBtn, #pasteBtn2, #closeBtn {
            padding: 15px 30px;
            font-size: 22px;
            cursor: pointer;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 8px;
            margin: 0 15px 25px 0;
            transition: background-color 0.3s;
        }
        #pasteBtn:hover, #pasteBtn2:hover, #closeBtn:hover {
            background-color: #45a049;
        }
        .label-text {
            color: #666;
            font-size: 24px;
            margin-right: 10px;
        }
        #markdownContent {
            border: 1px solid #ddd;
            padding: 30px;
            min-height: 300px;
            border-radius: 8px;
            font-size: 36px;
            line-height: 1.8;
            background-color: white;
            box-shadow: 0 2px 5px rgba(0,0,0,0.05);
            width: 100%;
        }
        .footer-text {
            margin-top: 20px;
            color: #666;
            font-size: 24px;
        }
    </style>
</head>
<body>
    <div class="header">
        <button id="pasteBtn2">剪贴板内容为：</button>
    </div>
    
    <div id="markdownContent">点击上下按钮粘贴剪切板</div>
    
    <div class="footer-text">
        <button id="pasteBtn">剪切板朗读完毕。（点击可替换）</button>
        </br>
        </br>
        </br>
        <button id="closeBtn">关闭</button>
        </br>
        </br>
        </br>
    </div>
    <script>
        const contentDiv = document.getElementById('markdownContent');
        
        // 页面加载完成后自动执行
        window.addEventListener('load', async () => {
            try {
                const text = await navigator.clipboard.readText();
                contentDiv.innerHTML = marked.parse(text);
            } catch (err) {
                console.error('读取剪贴板失败:', err);
                contentDiv.textContent = '读取剪贴板失败，请检查权限或点击按钮手动粘贴';
            }
        });
        
        // 绑定pasteBtn点击事件
        const pasteBtn = document.getElementById('pasteBtn');
        pasteBtn.addEventListener('click', async () => {
            try {
                const text = await navigator.clipboard.readText();
                contentDiv.innerHTML = marked.parse(text);
            } catch (err) {
                console.error('粘贴失败:', err);
                contentDiv.textContent = '粘贴失败，请检查权限或手动粘贴';
            }
        });
        
        // 绑定pasteBtn2点击事件（与pasteBtn功能一致）
        const pasteBtn2 = document.getElementById('pasteBtn2');
        pasteBtn2.addEventListener('click', async () => {
            try {
                const text = await navigator.clipboard.readText();
                contentDiv.innerHTML = marked.parse(text);
            } catch (err) {
                console.error('粘贴失败:', err);
                contentDiv.textContent = '粘贴失败，请检查权限或手动粘贴';
            }
        });

        // 绑定关闭按钮点击事件，关闭当前页面
        const closeBtn = document.getElementById('closeBtn');
        closeBtn.addEventListener('click', () => {
            window.close();
        });
    </script>
</body>
</html>
